package com.xz.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xz.R;
import com.xz.entity.Comment;
import com.xz.entity.Member;
import com.xz.entity.frontvo.CommentFrontVo;
import com.xz.service.CommentService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 评论 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2020-08-11
 */
@RestController
@RequestMapping("/video/comment")
public class CommentController {
     @Autowired
    private CommentService commentService;

     /*
     查询所有的评论
      */
     @GetMapping("getAllComment/{videoId}/{current}")
     public R getAllComment(@PathVariable String videoId,@PathVariable long current){
         //放入redis
         Map map=commentService.getAllComment(videoId,current);
         long total = (long) map.get("total");
         List<CommentFrontVo> commentFrontVoList= (List<CommentFrontVo>) map.get("records");
         return R.ok().data("total",total).data("commentList",commentFrontVoList);
     }

     /*
     发布评论
      */
     @PostMapping("/publishComment/{videoId}")
     public R publishComment(@PathVariable String videoId,@RequestBody CommentFrontVo commentFrontVo){
         commentFrontVo.setVideoId(videoId);
         Comment comment=new Comment();
         comment.setIsDeleted(0);
         BeanUtils.copyProperties(commentFrontVo,comment);
         commentService.save(comment);
         return R.ok();
     }
}

